package org.jsola.hr.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 一键发薪转账业务状态
 *
 * @author zhr
 */
public enum TransferAccountsSubjectStatusEnum implements IConst {

    /**
     * 待申请
     */
    WAIT_APPLICATION(1,"待申请"),
    /**
     * 审批中
     */
    APPROVE_ING(2,"审批中"),
    /**
     * 审批驳回
     */
    APPROVE_REJECT(3,"审批驳回"),
    /**
     * 待发放
     */
    WAIT_ISSUE(4,"待发放"),
    /**
     * 已发放
     */
    YET_ISSUE(5,"已发放");

    private final Integer value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "1,2,3,4,5";

     /**
     * 缓存所有value
     */
    private static final Map<Integer, TransferAccountsSubjectStatusEnum> LOOKUP = new HashMap<>();

    static {
        for (TransferAccountsSubjectStatusEnum e : TransferAccountsSubjectStatusEnum.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    TransferAccountsSubjectStatusEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找TransferAccountsSubjectStatusEnum
     * @param value value
     * @return TransferAccountsSubjectStatusEnum
     */
    public static TransferAccountsSubjectStatusEnum find(Integer value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找TransferAccountsSubjectStatusEnum
     * @param desc desc
     * @return TransferAccountsSubjectStatusEnum
     */
    public static TransferAccountsSubjectStatusEnum findByDesc(String desc){
        for (TransferAccountsSubjectStatusEnum e : TransferAccountsSubjectStatusEnum.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (TransferAccountsSubjectStatusEnum e : TransferAccountsSubjectStatusEnum.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        Integer value = (Integer) obj;
        return find(value) != null;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
